/**************************************************************************************************
	$Header: /pub/cvsroot/mydns/src/lib/misc.c,v 1.2 2002/08/31 05:51:34 bboy Exp $
	misc.c: Miscellaneous functions.

	Copyright (C) 2002  Don Moore <bboy@bboy.net>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at Your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
**************************************************************************************************/

#include "mydns.h"


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	COLUMN_EXISTS
	Returns 1 if the specified column exists in the specified table, 0 if it does not exist,
	or -1 if an error occurred.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
int
column_exists(mysql, table_name, column_name)
	MYSQL *mysql;
	const char * const table_name;
	const char * const column_name;
{
	MYSQL_RES *res = NULL;
	char query[512];
	size_t querylen;
	int rv;

	querylen = snprintf(query, sizeof(query),
		"SHOW COLUMNS FROM %s LIKE '%s'", table_name, column_name);

	if (mysql_real_query(mysql, query, querylen) || !(res = mysql_store_result(mysql)))
		return (-1);
	rv = mysql_num_rows(res);
	mysql_free_result(res);

	return (rv != 0);
}
/*--- column_exists() ---------------------------------------------------------------------------*/

/* vi:set ts=3: */
